home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
039a
/
cport1.zip
/
CPORT.H
< prev
next >
Wrap
Text File
|
1991-06-03
|
7KB
|
278 lines
/*
** CPORT.H
** Header file for Cport Serial Communications Library
**
** Copyright (c) 1991 Bri Productions
**
*/
#if defined __TURBOC__
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif
#elif defined __ZTC__
#define _Cdecl
#elif defined M_I86 && !defined __ZTC__
#if !defined NO_EXT_KEYS
#define _Cdecl cdecl
#else
#define _Cdecl
#endif
#endif
/*
**-------------------------------------
**
** com ports
**
**-------------------------------------
*/
#define COM1 0xC3F8 /* vector = 0xC, port base = 0x3F8 */
#define COM2 0xB2F8 /* vector = 0xB, port base = 0x2F8 */
#define COM3 0xC3E8 /* vector = 0xC, port base = 0x3E8 */
#define COM4 0xB2E8 /* vector = 0xB, port base = 0x2E8 */
/*
**-------------------------------------
**
** baud rate divisors
**
**-------------------------------------
*/
#define B115200 1
#define B57600 2
#define B38400 3
#define B19200 6
#define B9600 12
#define B7200 16
#define B4800 24
#define B3600 32
#define B2400 48
#define B2000 58
#define B1800 64
#define B1200 96
#define B600 192
#define B300 384
#define B150 768
#define B110 1047
#define B75 1536
#define B50 2304
/*
**-------------------------------------
**
** word lengths
**
**-------------------------------------
*/
#define W8 3
#define W7 2
#define W6 1
#define W5 0
#define WMASK 3
/*
**-------------------------------------
**
** stop bits
**
**-------------------------------------
*/
#define S1 0
#define S2 4
#define SMASK 1
/*
**-------------------------------------
**
** parity
**
**-------------------------------------
*/
#define NONE 0x00
#define ODD 0x08
#define EVEN 0x18
#define MARK 0x28
#define SPACE 0x38
#define PMASK 0x38
/*
**-------------------------------------
**
** handshaking
**
**-------------------------------------
*/
#define SOFT 1
#define HARD 2
/*
**-------------------------------------
**
** error codes
**
**-------------------------------------
*/
#define OVERUN 0x002 /* overrun error */
#define PARITY 0x004 /* parity error */
#define FRAMING 0x008 /* framing error */
#define BREAK 0x010 /* break detect */
#define TXFULL 0x100 /* transmit queue overflow */
#define RXFULL 0x200 /* receive queue overflow */
/*
**-------------------------------------
**
** status codes
**
**-------------------------------------
*/
#define DCTS 0x01 /* delta clear to send */
#define DDSR 0x02 /* delta data set ready */
#define TERI 0x04 /* trailing edge ring indicator */
#define DDCD 0x08 /* delta data carrier detect */
#define CTS 0x10 /* clear to send */
#define DSR 0x20 /* data set ready */
#define RI 0x40 /* ring indicator */
#define DCD 0x80 /* data carrier detect */
/*
**-------------------------------------
**
** byte typedef and parameter structure
**
**-------------------------------------
*/
#ifndef BYTE
#define BYTE
typedef unsigned char byte;
#endif
/** Do not change this structure **/
struct C_param{
unsigned com; /* com port */
int baud; /* baud rate */
byte mode; /* word length, stop bits, parity */
unsigned rxQ; /* receive queue size */
unsigned txQ; /* transmit queue size */
byte htype; /* handshaking type */
unsigned thresh; /* handshaking threshold (rx queue) */
};
/*
**-------------------------------------
**
** some other constants
**
**-------------------------------------
*/
#define ON 1
#define OFF 0
/*
**-------------------------------------
**
** ComOpen return codes
**
**-------------------------------------
*/
#define NO_ERR 0 /* no error */
#define OPENED 1 /* port already open */
#define BAD_COM 2 /* bad 'com' parameter */
#define NO_UART 3 /* no uart chip found */
#define RCV_ALC 4 /* receive queue allocation error */
#define TX_ALC 5 /* transmit queue allocation error */
/*
**-------------------------------------
**
** function macros
**
**-------------------------------------
*/
#define ComOut1(a) ComMcr(a, 0x04)
#define ComRts(a) ComMcr(a, 0x02)
#define ComDtr(a) ComMcr(a, 0x01)
#define ComReopen(a,b,c,d,e) ComOpen(a,b,c,d,e)
/*
**-------------------------------------
**
** function prototypes
**
**-------------------------------------
*/
/* control functions */
int _Cdecl ComOpen (unsigned com, int baud, byte mode, unsigned rxQ, unsigned txQ);
int _Cdecl ComOpenS (const struct C_param *param);
void _Cdecl ComParam (const struct C_param *param);
void _Cdecl ComClose (void);
void _Cdecl ComBaud (int baud);
void _Cdecl ComMode (byte mode);
void _Cdecl ComHandshake (byte htype, unsigned thresh);
void _Cdecl ComTx (byte on_off);
/* input functions */
char _Cdecl ComGetc (void);
char *_Cdecl ComGets (char *str, int max_c, char term_c);
unsigned _Cdecl ComIn (void *abyte, unsigned n_byte);
char _Cdecl ComPeek (void);
unsigned _Cdecl ComLenRx (void);
void _Cdecl ComFlushRx (void);
/* output functions */
int _Cdecl ComPutc (char c);
int _Cdecl ComPuts (const char *str);
unsigned _Cdecl ComOut (const void *abyte, unsigned n_byte);
unsigned _Cdecl ComLenTx (void);
void _Cdecl ComFlushTx (void);
/* status functions */
void _Cdecl ComMcr (byte on_off, byte bits);
unsigned _Cdecl ComError (void);
byte _Cdecl ComStatus (void);
/* misc fuctions */
void _Cdecl ComSetBreak (void);
void _Cdecl ComClrBreak (void);
void _Cdecl ComPutScrtch (byte abyte);
byte _Cdecl ComGetScrtch (void);
byte _Cdecl ComChecksum (const void *abyte, unsigned n_byte);
unsigned _Cdecl ComCrc16 (const void *abyte, unsigned n_byte);